package com.learn.post_processor;

import com.learn.post_processor.beans.service.UserServiceImpl;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

public class BeanPostProcessorImpl implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("(before)BeanPostProcessorImpl：（每次创建Bean）遍历beanDefinitionMap每次创建Bean实例对象后，填充进入singletonObjects前");
        System.out.println("(before)beanName:" + beanName);
        
        // 设置属性
        if (bean instanceof UserServiceImpl) {
            UserServiceImpl userService = (UserServiceImpl) bean;
            userService.setName("hhhh");
        }
        
        return bean;
    }
    
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("(after)BeanPostProcessorImpl：（每次创建Bean）遍历beanDefinitionMap每次创建Bean实例对象后，填充进入singletonObjects前");
        System.out.println("(after)beanName:" + beanName);
        
        return bean;
    }
}
